
import tornado.web
import tornado.ioloop
import tornado.options
from tornado.options import define, options

from handlers import main, auth

define("port", default="8080", help="run port", type=int)


class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/", main.IndexHandler),
            (r"/upload", main.UploadHandler),
            (r"/login", auth.LoginHandler),
            (r"/logout", auth.LogoutHandler),
            (r"/signup", auth.SignupHandler),
        ]
        settings = dict(
            debug=True,
            template_path="templates",
            static_path="static",
            cookie_secret="qwe123",
            login_url="/login",
            pycket={
                "engine": "redis",
                "storage": {
                    "host": "localhost",
                    "port": 6379,
                    "max_connections": 2**10,
                    "db_sessions": 5
                },
                "cookies": {
                    "expires_days": 7
                }
            }
        )
        super().__init__(handlers, **settings)


application = Application()


if __name__ == '__main__':
    tornado.options.parse_command_line()
    application.listen(options.port)
    tornado.ioloop.IOLoop.current().start()
